from typing import List, Optional, Dict, Any
from src import retMes
from sqlalchemy.orm import Session
from src.models import sys_entity_i18n as sysEntityI18nModels
from src.schemas.login_manager import AuthManager


def get_entity_i18n_value(
        default_entity_value: Optional[str],
        entity_type: Optional[str],
        entity_id: Optional[str],
        db: Session,
        auth: AuthManager
):
    """
        获取实体的国际化翻译值

        Args:
            default_entity_value (Optional[str]): 当找不到对应国际化配置时返回的默认值
            entity_type (Optional[str]): 实体类型，用于区分不同种类的实体
            entity_id (Optional[str]): 实体唯一标识符
            db (Session): SQLAlchemy数据库会话对象，用于执行数据库查询
            auth (AuthManager): 认证管理器对象，包含当前用户的认证信息

        Returns:
            返回对应实体的国际化值，如果未找到匹配记录则返回 default_entity_value
        """

    api_id = auth.api_id
    language = auth.language
    entity_i18n = db.query(sysEntityI18nModels.SysEntityI18n).filter(sysEntityI18nModels.SysEntityI18n.api_id == api_id,
                                                                     sysEntityI18nModels.SysEntityI18n.entity_type == entity_type,
                                                                     sysEntityI18nModels.SysEntityI18n.language == language,
                                                                     sysEntityI18nModels.SysEntityI18n.entity_id == entity_id,
                                                                     ).first()
    if entity_i18n:
        return entity_i18n.entity_value
    else:
        return default_entity_value
